﻿
<span style="@Style" class="@Class">@TransformDateTime()</span>

@code {
    [Parameter]
    public DateTime Value { get; set; }

    [Parameter]
    public string? Style { get; set; }

    [Parameter]
    public string? Class { get; set; }

    [Parameter]
    public Func<DateTime, string>? Format { get; set; }

    [Inject]
    private I18n I18n { get; set; } = default!;

    [Inject]
    private JsInitVariables JsInitVariables { get; set; } = default!;

    private string TransformDateTime()
    {
        var dateTime = Value.Add(JsInitVariables.TimezoneOffset);

        if (Format != null)
        {
            return Format(dateTime);
        }
        else
        {
            return dateTime.ToString(I18n.T("$DateTimeFormat"));
        }
    }
}
